package com.wz.boot.listener;

import com.wz.boot.constant.Constant;
import love.forte.common.ioc.annotation.Beans;
import love.forte.common.ioc.annotation.Depend;
import love.forte.simbot.annotation.*;
import love.forte.simbot.api.message.MessageContentBuilderFactory;
import love.forte.simbot.api.message.assists.Flag;
import love.forte.simbot.api.message.events.FriendAddRequest;
import love.forte.simbot.api.message.events.FriendIncrease;
import love.forte.simbot.api.message.events.FriendReduce;
import love.forte.simbot.api.message.events.MsgGet;
import love.forte.simbot.api.sender.BotSender;
import love.forte.simbot.api.sender.MsgSender;
import love.forte.simbot.api.sender.Sender;
import love.forte.simbot.component.mirai.message.event.MiraiFriendDeleted;
import love.forte.simbot.component.mirai.message.event.MiraiFriendRequest;
import love.forte.simbot.constant.PriorityConstant;
import net.mamoe.mirai.contact.Friend;
import net.mamoe.mirai.contact.Stranger;
import net.mamoe.mirai.event.events.FriendDeleteEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 监听好友增加事件
 */
@Component
public class OnFriendIncreaseListener {
    static final Logger logger = LoggerFactory.getLogger(OnFriendIncreaseListener.class);

    @Autowired
    private Constant constant;

    /**
     * 监听好友增加，并报告管理员
     * @param friendIncrease
     * @param sender
     */
    @OnFriendIncrease
    public void OnFriendIncrease(FriendIncrease friendIncrease,Sender sender){
        sender.sendPrivateMsg(constant.getAdminQQ(),"好友增加："+friendIncrease.getAccountInfo().getAccountCode()+",昵称："+friendIncrease.getAccountInfo().getAccountNickname());
    }

    /**
     * 监听好友减少，并报告管理员
     * @param friendReduce
     * @param sender
     */
    @Listens(value = @Listen(MiraiFriendDeleted.class))
    public void friendDelete1(FriendReduce friendReduce, Sender sender){
        sender.sendPrivateMsg(constant.getAdminQQ(),"好友减少："+friendReduce.getAccountInfo().getAccountCode()+",昵称："+friendReduce.getAccountInfo().getAccountNickname());
    }

    /**
     * 自动同意好友申请
     * @param friendAddRequest
     * @param msgSender
     */
    @OnFriendAddRequest
    public void OnFriendAddReque(FriendAddRequest friendAddRequest, MsgSender msgSender){
        Flag<? extends FriendAddRequest.FlagContent> flag = friendAddRequest.getFlag();
        msgSender.SETTER.setFriendAddRequest(flag,"",true,false);
        String accountCode = friendAddRequest.getAccountInfo().getAccountCode();
        logger.info("好友请求。。。同意   QQ{}",accountCode);
        msgSender.SENDER.sendPrivateMsg(constant.getAdminQQ(),"好友增加："+friendAddRequest.getAccountInfo().getAccountCode()+",昵称："+friendAddRequest.getAccountInfo().getAccountNickname());
    }



}
